package com.uraurora.crescent.advanced.tree;

import java.util.Iterator;

/**
 * @author : gaoxiaodong04
 * @program : crescent
 * @date : 2020-01-05 20:01
 * @description : 抽象的线段树类，具有单点更新，单点查询，区间更新，区间查询的功能
 */
public abstract class AbstractSegmentTree<T> implements ISegmentTree<T>, Iterable<T>{

    @Override
    public abstract boolean update(int index, T value);

    @Override
    public abstract boolean update(int left, int right, T value);

    @Override
    public abstract T query(int index, T initValue);

    @Override
    public abstract T query(int left, int right, T initValue);

    @Override
    public abstract Iterator<T> iterator();

    public abstract int size();

    //<editor-fold desc="Static Methods">
    protected static void checkIndexRange(int index, int min, int max){
        if(index < min || index > max){
            throw new IndexOutOfBoundsException("index:"+index+", where bounds min:"+min+" and max:"+max);
        }
    }
    //</editor-fold>
}
